lib/boot: Convert bootconfig parser to new code style
authorColin Walters <walters@verbum.org>
Thu, 13 Apr 2017 00:50:53 +0000 (20:50 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 19 Apr 2017 13:26:20 +0000 (13:26 +0000)
This is a small one.

Closes: #790
Approved by: jlebon

src/libostree/ostree-bootconfig-parser.c

index 8031334ec30d4b02f1948e63b80b5b87c9d993b3..a7c473ddb7772cb176b4678457f7ddb16f0eab59 100644 (file)
@@ -79,23 +79,18 @@ ostree_bootconfig_parser_parse_at (OstreeBootconfigParser  *self,
                                    GCancellable            *cancellable,
                                    GError                 **error)
 {
-  gboolean ret = FALSE;
-  g_autofree char *contents = NULL;
-  char **lines = NULL;
-  char **iter = NULL;
-
   g_return_val_if_fail (!self->parsed, FALSE);
 
-  contents = glnx_file_get_contents_utf8_at (dfd, path, NULL, cancellable, error);
+  g_autofree char *contents = glnx_file_get_contents_utf8_at (dfd, path, NULL, cancellable, error);
   if (!contents)
-    goto out;
+    return FALSE;
 
-  lines = g_strsplit (contents, "\n", -1);
-  for (iter = lines; *iter; iter++)
+  g_auto(GStrv) lines = g_strsplit (contents, "\n", -1);
+  for (char **iter = lines; *iter; iter++)
     {
       const char *line = *iter;
       char *keyname = "";
-      
+
       if (g_ascii_isalpha (*line))
         {
           char **items = NULL;
@@ -115,11 +110,8 @@ ostree_bootconfig_parser_parse_at (OstreeBootconfigParser  *self,
     }
 
   self->parsed = TRUE;
-  
-  ret = TRUE;
- out:
-  g_strfreev (lines);
-  return ret;
+
+  return TRUE;
 }
 
 gboolean
@@ -166,16 +158,10 @@ ostree_bootconfig_parser_write_at (OstreeBootconfigParser   *self,
                                    GCancellable             *cancellable,
                                    GError                  **error)
 {
-  gboolean ret = FALSE;
-  GHashTableIter hashiter;
-  gpointer hashkey, hashvalue;
-  GString *buf = g_string_new ("");
-  guint i;
-  g_autoptr(GHashTable) written_overrides = NULL;
+  g_autoptr(GString) buf = g_string_new ("");
+  g_autoptr(GHashTable) written_overrides = g_hash_table_new (g_str_hash, g_str_equal);
 
-  written_overrides = g_hash_table_new (g_str_hash, g_str_equal);
-
-  for (i = 0; i < self->lines->len; i++)
+  for (guint i = 0; i < self->lines->len; i++)
     {
       GVariant *linedata = self->lines->pdata[i];
       const char *key;
@@ -197,6 +183,8 @@ ostree_bootconfig_parser_write_at (OstreeBootconfigParser   *self,
         }
     }
 
+  GHashTableIter hashiter;
+  gpointer hashkey, hashvalue;
   g_hash_table_iter_init (&hashiter, self->options);
   while (g_hash_table_iter_next (&hashiter, &hashkey, &hashvalue))
     {
@@ -208,15 +196,11 @@ ostree_bootconfig_parser_write_at (OstreeBootconfigParser   *self,
   if (!glnx_file_replace_contents_at (dfd, path, (guint8*)buf->str, buf->len,
                                       GLNX_FILE_REPLACE_NODATASYNC,
                                       cancellable, error))
-    goto out;
+    return FALSE;
 
-  ret = TRUE;
- out:
-  if (buf)
-    g_string_free (buf, TRUE);
-  return ret;
+  return TRUE;
 }
-           
+
 gboolean
 ostree_bootconfig_parser_write (OstreeBootconfigParser   *self,
                                 GFile            *output,